package com.zwh.modules.order.service;

import org.aspectj.weaver.ast.Or;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zwh.common.idgen.IdGenerate;
import com.zwh.modules.goods.dao.GoodsDao;
import com.zwh.modules.goods.entity.Goods;
import com.zwh.modules.order.dao.OrderDao;
import com.zwh.modules.order.entity.Order;
import com.baomidou.mybatisplus.extension.service.IService;

/**
 * <p>
 *  服务类
 * </p>
 *
 * @author zhangwenhe
 * @since 2020-10-27
 */
@Service
public class OrderService extends ServiceImpl<OrderDao, Order> {

    @Transactional(readOnly = false)
    public Order createOrder(String userId, Goods goods) {
        Order order = new Order();
        order.setId(IdGenerate.nextId());
        order.setGoodsId(goods.getId());
        order.setUserId(userId);
        order.setMoney(goods.getGoodsPrice());
        this.save(order);
        return order;
    }
}
